package com.hainatong.shiphelper.module.workermgr.fragment;

import android.os.Bundle;
import com.blankj.utilcode.util.ObjectUtils;
import com.blankj.utilcode.util.StringUtils;
import com.hainatong.shiphelper.MvvmLazyFragment;
import com.hainatong.shiphelper.R;
import com.hainatong.shiphelper.databinding.FragmentSalaryInfoBinding;
import com.hainatong.shiphelper.module.workermgr.entity.WorkerBean;
import com.hainatong.shiphelper.module.workermgr.viewmodel.OrgUserViewModel;
import com.hainatong.shiphelper.utils.GsonUtil;

import android.view.View;

/**
 *  员工 工资信息
 */
public class WorkerSalaryInfoFragment extends MvvmLazyFragment<FragmentSalaryInfoBinding, OrgUserViewModel>
{
    private static String WORKER_SALARY_INFO_TAG = "WorkerSalaryInfoFragment";

    private WorkerBean mUserInfo;

    public static WorkerSalaryInfoFragment newInstance(String scanCode)
    {
        Bundle bundle = new Bundle();
        bundle.putString( WORKER_SALARY_INFO_TAG , scanCode );
        WorkerSalaryInfoFragment mWorkerFragment = new WorkerSalaryInfoFragment();
        mWorkerFragment.setArguments( bundle );
        return mWorkerFragment;
    }

    @Override
    public int getLayoutId()
    {
        return R.layout.fragment_salary_info;
    }

    @Override
    public int getBindingVariable()
    {
        return 0;
    }

    @Override
    protected void onRetryBtnClick()
    {
    }

    @Override
    protected void initParameters()
    {
        Bundle args = getArguments();
        if(  args != null )
        {
            String workerInfoStr = args.getString(WORKER_SALARY_INFO_TAG , "");
            if( !StringUtils.isEmpty( workerInfoStr ) )
            {
                mUserInfo = GsonUtil.json2Obj( workerInfoStr , WorkerBean.class);
            }
        }
    }



    @Override
    protected void initView(View view)
    {

        if(ObjectUtils.isNotEmpty( mUserInfo ))
        {
            viewDataBinding.setSalaryInfo( mUserInfo );
            viewDataBinding.executePendingBindings();
        }
    }

    @Override
    protected void lazyLoad()
    {
        if( ObjectUtils.isNotEmpty( mUserInfo ) )
        {
            //直接查询 改用户 的证书
            viewModel.queryUserCertByUuid( mUserInfo.getUuid() );
        }
        // 拿到证书 列表
        viewModel.getCertListResult().observe( this ,result -> {
            if( result.isSuccess() )
            {
                // 处理显示信息
            }
            else
            {
            }
        } );
    }

}
